from langchain_openai import ChatOpenAI
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser

#创建prompt AIGC
prompt_template = PromptTemplate(
    input_variables=["product"],
    template="为{product}写3个吸引人的广告语，需要面向年轻人",
)
prompt = prompt_template.invoke({"product":"cursor"})


#创建模型
model = ChatOpenAI(
    model_name = "qwen-plus",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key="sk-10a2497575a04b1184b62bba5f00d6e2",
    temperature=0.7
)

#调用大模型
response = model.invoke(prompt)

#print(response.content) 

#创建输出解析器
out_parser = StrOutputParser()
answer = out_parser.invoke(response)
print(answer)



